//
//  XGStatusCommentViewModel.swift
//  TodayNews
//
//  Created by monkey on 2020/3/14.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit
import YYText

class XGStatusCommentViewModel
{
    /// 用户名
    var userName: String? {
        return statusCommentModel.user != nil ? statusCommentModel.user?.screen_name : statusCommentModel.user_name
    }
    /// 用户头像
    var userIcon: String? {
        return statusCommentModel.user != nil ? statusCommentModel.user?.avatar_url : statusCommentModel.user_profile_image_url
    }
    /// 是否认证
    var isUserVerified: Bool {
        return statusCommentModel.user != nil ? statusCommentModel.user!.user_verified : statusCommentModel.user_verified
    }
    
    /// 发布时间
    private(set) var createTime: String
    /// 点赞数
    private(set) var diggCount: String
    /// 行高
    private(set) var rowHeight: CGFloat = 0
    /// 内容富文本
    private(set) var contentAttributeString: NSAttributedString

    init(statusCommentModel: XGStatusCommentModel)
    {
        createTime = Date.convertToCreateString(sinceNow: TimeInterval(statusCommentModel.create_time))
        diggCount = statusCommentModel.digg_count.countString
        rowHeight += 10 + 15
        contentAttributeString = XGEmojiManager.shared.convertToAttributeString(contnet: statusCommentModel.text ?? "", fontSize: 15, textColor: UIColor.darkGray)
        rowHeight += 20 + XGCalculator.calculateAttributeString(text: contentAttributeString, width: TodayNews_Screen_Width - 60)
        rowHeight = 10 + 20 + ceil(rowHeight)
        
        self.statusCommentModel = statusCommentModel
    }
    
    /// 动态评论数据模型
    private let statusCommentModel: XGStatusCommentModel
}
